<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取一组元素</title>
    <style>
        div{
            width:200px;height:200px; float:left; border:1px solid black;
            margin:10px;
        }
    </style>
    <script>
        window.onload=function(){
            var aDiv=document.getElementsByTagName('div');
            for(var i=0; i<aDiv.length; i++){
                aDiv[i].style.background='red';
            }
           // alert(aDiv.length);
          //  aDiv.style.background='red';
            /*
            aDiv[0].style.background='red';
            aDiv[1].style.background='green';
            aDiv[2].style.background='yellow';
            aDiv[3].style.background='black';
            */
            //一个一个去指定背景颜色太麻烦了
        };
    </script>
</head>
<body>
 <div></div>
 <div></div>
 <div></div>
 <div></div>

</body>
</html>
<!--getElementSByTagName是获取一组元素-->